#include "AICtrler.h"
#include "util/Util.h"
#include "communication/DataPacket.h"
#include "Assembler.h"
AICtrler::AICtrler(Assembler* pAssm):
MasterControl(pAssm)
{

}

AICtrler::~AICtrler()
{

}

ErrorCode AICtrler::Init()
{
	m_MoveCmd.push_back( MoveCommand(bNoAction,1000) );
	m_MoveCmd.push_back( MoveCommand(eMoveFront,10000) );
	m_MoveCmd.push_back( MoveCommand(eMoveStop,500) );
	m_MoveCmd.push_back( MoveCommand(eMoveLeft,3000) );
	m_MoveCmd.push_back( MoveCommand(eMoveStop,500) );
	m_MoveCmd.push_back( MoveCommand(eMoveFront,10000) );
	m_MoveCmd.push_back( MoveCommand(eMoveStop,500) );
	m_MoveCmd.push_back( MoveCommand(eMoveLeft,3000) );
	m_MoveCmd.push_back( MoveCommand(eMoveStop,500) );
	m_MoveCmd.push_back( MoveCommand(eMoveFront,10000) );
	m_MoveCmd.push_back( MoveCommand(eMoveStop,500) );
	m_MoveCmd.push_back( MoveCommand(eMoveLeft,3000) );
	m_MoveCmd.push_back( MoveCommand(eMoveStop,500) );
	m_MoveCmd.push_back( MoveCommand(eMoveFront,10000) );
	m_MoveCmd.push_back( MoveCommand(eMoveStop,500) );
	m_MoveCmd.push_back( MoveCommand(eMoveLeft,3000) );
	m_MoveCmd.push_back( MoveCommand(eMoveStop,500) );
	m_MoveCmd.push_back( MoveCommand(eMoveFront,10000) );
	m_MoveCmd.push_back( MoveCommand(eMoveStop,500) );
	m_MoveCmd.push_back( MoveCommand(eMoveLeft,3000) );
	m_MoveCmd.push_back( MoveCommand(eMoveStop,500) );
	this->OnReady(0);
	return eOK;
}

ErrorCode AICtrler::PushData(char* pData, uint32 nLen)
{
	return eOK;
}

ErrorCode AICtrler::OnReceive( DataPacket& pack )
{
	return eOK;
}


ErrorCode AICtrler::Update(uint32 dtTime)
{
	if(	m_MoveCmd.empty())
		return eOK;

	if( m_MoveCmd.front().tmKeepMS > dtTime )
	{
		m_MoveCmd.front().tmKeepMS -= dtTime;
	}else{
		m_MoveCmd.pop_front();
		if ( m_MoveCmd.empty() )
			return eOK;

		Shifter* pShifter = dynamic_cast<Shifter*>(this->GetAssembler()->GetOrgan(eShifter,0) );
		if( pShifter )
		{
			pShifter->Move(m_MoveCmd.front().moveType );
		}
	
	}
	
	return eOK;
}

void AICtrler::OnReady(uint32 errCode)
{
	MasterControl::OnReady( errCode );
	_LOG("AICtrler Ready![%d]",errCode);
}